package demolinkedlist;

import java.util.LinkedList;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {

        //双向链表的实例化
        LinkedList<Integer> list = new LinkedList<>();

        list.addLast(1);//尾插法
        list.addLast(12);
        list.addLast(13);
        list.addFirst(17);//头插法

        //可使用sout直接输出
        System.out.println(list);

        //使用迭代器输出(正向遍历)
        ListIterator<Integer> it = list.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
    }


    //测试removeAllKey
    public static void main5(String[] args) {

        MyLinkedList myLinkedList = new MyLinkedList();

        myLinkedList.addLast(1);
        myLinkedList.addLast(4);
        myLinkedList.addLast(3);
        myLinkedList.addLast(4);
        myLinkedList.display();

        myLinkedList.removeAllKey(4);
        myLinkedList.display();
    }


    //测试remove
    public static void main4(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();

        //myLinkedList.addLast(1);
        //myLinkedList.addLast(2);
        //myLinkedList.addLast(3);
        myLinkedList.addLast(4);
        myLinkedList.display();

        myLinkedList.remove(4);
        myLinkedList.display();
    }


    //addIndex测试
    public static void main3(String[] args) {

        MyLinkedList myLinkedList = new MyLinkedList();

        myLinkedList.addLast(1);
        myLinkedList.addLast(2);
        myLinkedList.addLast(3);
        myLinkedList.addLast(4);
        myLinkedList.display();

        myLinkedList.addIndex(2, 33);
        myLinkedList.display();
    }


    //addLast测试
    public static void main2(String[] args) {

        MyLinkedList myLinkedList = new MyLinkedList();

        myLinkedList.addLast(1);
        myLinkedList.addLast(2);
        myLinkedList.addLast(3);
        myLinkedList.addLast(4);//快速复制：ctrl + d

        myLinkedList.display();
    }


    //addFirst和display测试
    public static void main1(String[] args) {

        MyLinkedList myLinkedList = new MyLinkedList();

        myLinkedList.addFirst(1);
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(4);//快速复制：ctrl + d

        myLinkedList.display();
    }
}
